/****************************************************************
 * <strong>MFModelAndView</strong>
 *
 * <p>
 * MFModelAndView
 * </p>
 *
 * @author AndyZhang 2013
 * @version 0.1
 * ToDo:2013-3-3
 ***************************************************************/
package com.thinkwide.data.mvc.view;

import com.thinkwide.data.mvc.core.IMFView;

import java.util.HashMap;
import java.util.Map;

public class MFModelAndView {
    private String ViewName;
    private Map<String, Object> model;
    private IMFView View;

    public MFModelAndView() {
        model = new HashMap<String, Object>();
    }

    public MFModelAndView(IMFView view) {
        this();
        View = view;
    }

    public MFModelAndView(IMFView view, String modelName, Object modelObject) {
        this(view);
        model.put(modelName, modelObject);
    }

    public MFModelAndView(IMFView view, Map<String, Object> model) {
        this(view);
        this.model.putAll(model);
    }

    public MFModelAndView(String viewName) {
        this();
        ViewName = viewName;
    }

    public Map<String, Object> getModel() {
        return model;
    }

    public MFModelAndView(String viewName, String modelName, Object modelObject) {
        this(viewName);
        model.put(modelName, modelObject);
    }

    public MFModelAndView(String viewName, Map<String, Object> model) {
        this(viewName);
        this.model.putAll(model);
    }

    public MFModelAndView addObject(Object obj) {
        model.put(obj.getClass().getSimpleName(), obj);
        return this;
    }

    public MFModelAndView addObject(String name, Object obj) {
        model.put(name, obj);
        return this;
    }

    public MFModelAndView addAllObjects(Map<String, Object> model) {
        this.model.putAll(model);
        return this;
    }

    public void clear() {
        model.clear();
    }

    public boolean isEmpty() {
        return model.isEmpty();
    }

    public void setViewName(String viewName) {
        ViewName = viewName;
    }

    public String getViewName() {
        return ViewName;
    }

    public void setView(IMFView view) {
        View = view;
    }

    public IMFView getView() {
        return View;
    }

}
